﻿using OpenTK.Graphics.OpenGL4;
using OpenTK.Mathematics;

namespace TrinityEngine
{
    public class SimpleSpriteMaterial : Material
    {
        private Texture _texture;

        public SimpleSpriteMaterial()
        {
            _shader = new Shader("res/shaders/Simple Sprite.shader");
        }

        public override void Bind()
        {
            GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
            GL.Enable(EnableCap.Blend);

            _shader.Bind();
            _texture.Bind(0);
            _shader.SetUniform1i("_MainTex", 0);
        }

        public void SetUniform(Matrix4 mvp)
        {
            _shader.Bind();
            _shader.SetUniformMat4("u_mvp", mvp);
        }

        public void SetTexture(Texture texture)
        {
            _texture = texture;
        }

        public override void Unbind()
        {
            _shader.Unbind();
            _texture.Unbind();
        }

        protected override void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (disposing)
            {

            }

            /*_texture.Dispose();*/

            base.Dispose(disposing);
        }
    }
}
